<?php
require_once 'libraries/Utilities/function.php';
$path = "../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);
$films = mreadFile($path);
$rating = NULL;
$rating1 = NULL;
?>
<form method="POST">
    <input type="text" name="rating">
    <input type="text" name="rating1">
    <input type="submit" name="submit" value="Search">
</form>

<?php if (isset($_POST['submit'])): ?>
    <?php $rating = (int) $_POST['rating']; ?>
    <?php $rating1 = (int) $_POST['rating1']; ?>
<?php endif; ?>
<?php foreach ($films as $item): ?>
    <?php
    $film = explode(";", $item);
    $item = trim($item);
    if (!empty($item))
        
    ?>
    <?php if (empty($rating) && empty($rating1)): ?>
        <?php if (isset($film[2]) || isset($film[3])): ?>
        <?php echo $film[0]?>
            <img src = '../ptnhuan-web1/public/images/films/<?php echo $film[1] ?>'> 
            <?php echo $film[2] ?>
            <?php echo $film[3] ?>
            <a href="edit.php?if= <?php echo $film[0]?> ">Edit</a>
           <br>
        <?php endif; ?>
    <?php else: ?>
        <?php if (isset($film[2]) || isset($film[3])): ?>
            <?php if (($rating < (int) $film[2]) && ($rating1 > (int) $film[3])): ?>
                <img src = '../ptnhuan-web1/public/images/films/<?php echo $film[1] ?>'> 
                <?php echo $film[2] ?>
                <?php if (!empty($film[3])) echo $film[3] ?>
               <a href="edit.php?if= "<?php echo $film[0]?> >Edit</a>
               <br> 
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
<?php endforeach; ?>   